package com.hsxc.cdz.monitor.bean.second;

import com.hsxc.cdz.base.util.BytesUtil;
import com.hsxc.cdz.mgmt.GlobalManager;
import com.hsxc.cdz.monitor.FSM.CachePile;

/**
 * 空闲时充电上送报文
 * @author llw
 *
 */
public class HeartPileMsg extends SecMessage{
	private byte state;  //充电桩状态  //1:空闲中，2：充电中，3：故障中，4：维护中，5：满电占用中
    //6:未满电占用中    未满电占用中：在未充满电的情况下停止充电，但充电枪尚未拔出
    private byte plug;   //充电枪状态  1：未连接； 2：完全按揭 
    private byte park;   //停车位状态  1：未占用；2：已占用
    private int count;  ///电度表计数
	private Fault fault; //故障信息
	private Errcode errcode; //错误码
	
	public static final int length = 24;
	public static final int length_state = 1;
	public static final int length_plug = 1;
	public static final int length_park = 1;
	public static final int length_count = 4;
	public static final int length_fault = 1;
	public static final int length_errcode = 1;
	
	public static final int plug_false = 1;
	public static final int plug_true = 2;
	public static final int park_false = 1;
	public static final int park_true = 2;
	/********************************************************************************/
	//构造方法
	public HeartPileMsg(){
		super();
	}
	public HeartPileMsg(byte[] data){
		setMessage(data);
	}
	/********************************************************************************/
	//重写父类抽象方法
	@Override
	public byte[] getMessage() {
		return null;
	}

	@Override
	public void setMessage(byte[] data) {
		super.setMessage(data);
		int temp = SecMessage.length;
		this.state = data[temp];
		temp = temp + length_state;
		this.plug = data[temp];
		temp = temp+length_plug;
		this.park = data[temp];
		temp = temp+length_park;
		this.count = BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp, length_count, data));
		temp = temp+length_count;
		this.fault = new Fault(data[temp]);
		temp = temp +length_fault;
		this.errcode = new Errcode(data[temp]);
	}

	@Override
	public boolean execute() {
		CachePile pile = GlobalManager.pileManager.getPile(this.getPileNO());
		if(plug==plug_false){
			pile.setInserted(false);
		}else{
			pile.setInserted(true);
		}
		if(park==park_false){
			pile.setPark(false);
		}else{
			pile.setPark(true);
		}
	//	pile.setFault(fault.getFault());
		String s = errcode.getErrcode();
		if(!s.equals(Fault.NOMAL)){
		//	pile.setFault(s);
		}
		HeartSerMsg heart = new HeartSerMsg(getPileNO());
		heart.execute();
		return true;
	}
	
	/******************************************************************************/
	//get() and set()

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
	public byte getState() {
		return state;
	}
	public void setState(byte state) {
		this.state = state;
	}
	public byte getPlug() {
		return plug;
	}
	public void setPlug(byte plug) {
		this.plug = plug;
	}
	public byte getPark() {
		return park;
	}
	public void setPark(byte park) {
		this.park = park;
	}
	public Fault getFault() {
		return fault;
	}
	public void setFault(Fault fault) {
		this.fault = fault;
	}
	public Errcode getErrcode() {
		return errcode;
	}
	public void setErrcode(Errcode errcode) {
		this.errcode = errcode;
	}
}
